/*
    25. Write a program in C to replace the spaces of a string with a specific character. 

    Test Data :
    Input a string : Be glad to see the back of 
    Input replace character : *

    Expected Output :

    After replacing the space with  * the new string is :                 
    Be*glad*to*see*the*back*of*
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_LEN 1024
#define MAX_STR 256

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p++ = ch;
    }
    *p = '\0';
    return str;
}

char* replaceby(char *str, char ch)
{
    char *p = str;
    while(*str){
        if(*str == ' '){
            *str = ch;
        }
        str++;
    }
    return p;
}

int main(void)
{
    char *str = malloc(MAX_LEN);
    char ch;
    printf("Input a string : ");
    getstr(str);
    printf("Input replace character : ");
    scanf("%c", &ch);
    replaceby(str, ch);
    printf("After replacing the space with %c the new string is : \n%s", ch, str);

    return 0;
}